import 'package:async/async.dart';
import 'package:boss/main.dart';
import 'package:boss/models/coupon.dart';
import 'package:flutter/material.dart';

class CouponListProvider extends ChangeNotifier {
  List<Coupon> validCouponList = [];
  List<Coupon> invalidCouponList = [];

  Future<Result<List<Coupon>>> queryCoupons(int type) async {
    final res = await (type == 0 ? api.queryValidCouponList() : api.queryValidCouponList());
    if (!res.successful()) {
      return Result.error(res.msg);
    }

    if (type == 0) {
      validCouponList = res.data;
    } else {
      invalidCouponList = res.data;
    }
    notifyListeners();

    return Result.value(res.data);
  }

  Future<Result<List<Coupon>>> queryValidCouponList() {
    return queryCoupons(0);
  }

  Future<Result<List<Coupon>>> queryInvalidCouponList() {
    return queryCoupons(1);
  }
}
